package br.com.management.mentor.model.entities.view;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

import br.com.management.mentor.model.entities.auth.Permission;

@Entity
public class Menu {

	@Id
	@GeneratedValue( strategy = GenerationType.IDENTITY )
	private Long id;

	@NotEmpty
	@Length( max = 80 )
	@Column( nullable = false , unique = true , length = 80 , updatable = false )
	private String key;

	@OneToOne
	private Permission permission;

	@NotEmpty
	@Length( max = 255 )
	@Column( nullable = false , length = 255 , updatable = false )
	private String image;

	@NotNull
	@Column( nullable = false , updatable = false )
	@Temporal( TemporalType.TIMESTAMP )
	private Date creationDate;

	public Long getId() {
		return id;
	}

	public void setId( Long id ) {
		this.id = id;
	}

	public String getKey() {
		return key;
	}

	public void setKey( String key ) {
		this.key = key;
	}

	public Permission getPermission() {
		return permission;
	}

	public void setPermission( Permission permission ) {
		this.permission = permission;
	}

	public String getImage() {
		return image;
	}

	public void setImage( String image ) {
		this.image = image;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate( Date creationDate ) {
		this.creationDate = creationDate;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append( key ).append( creationDate ).toHashCode();
	}

	@Override
	public boolean equals( Object obj ) {
		if ( !( obj instanceof Menu ) )
			return false;
		Menu other = (Menu) obj;
		return new EqualsBuilder().append( key , other.key ).isEquals();
	}

}